package com.xbongbong.saas.service;

import com.alibaba.fastjson.JSONObject;
import com.xbongbong.paas.domain.entity.ext.PaasFormDataEntityExt;
import com.xbongbong.paas.field.FieldAttrEntity;
import com.xbongbong.paas.pojo.FieldAttrEntityForImport;
import com.xbongbong.paas.pojo.dto.FormDataAddDTO;
import com.xbongbong.paas.pojo.dto.FormDataListDTO;
import com.xbongbong.paas.pojo.dto.ImportFormDataDTO;
import com.xbongbong.paas.pojo.dto.SaasFormSaveDTO;
import com.xbongbong.paas.pojo.dto.ValidateDataDTO;
import com.xbongbong.paas.pojo.imports.CellTitlePojo;
import com.xbongbong.paas.pojo.imports.RowGroupPojo;
import com.xbongbong.paas.toolbox.exception.XbbException;
import com.xbongbong.pro.businessdata.pojo.dto.FormatExplainDTO;
import com.xbongbong.pro.businessproduct.pojo.dto.BusinessProductListDTO;
import com.xbongbong.pro.detailtab.dto.ChangeDocumentStatusSaveDTO;
import com.xbongbong.pro.detailtab.vo.ChangeDocumentStatusSaveVO;
import com.xbongbong.pro.detailtab.vo.ProductSummaryVO;
import com.xbongbong.pro.listbatch.pojo.dto.AddLabelDTO;
import com.xbongbong.pro.product.pojo.ProductSavePojo;
import com.xbongbong.pro.product.pojo.dto.PagingProductDTO;
import com.xbongbong.pro.product.pojo.vo.PagingProductVO;
import com.xbongbong.pro.transfer.pojo.dto.TransferDeleteBatchDTO;
import com.xbongbong.pro.transfer.pojo.dto.TransferEditAttrUpdateDTO;
import com.xbongbong.pro.transfer.pojo.dto.TransferResetInstockIdDTO;
import com.xbongbong.pro.transfer.pojo.dto.TransferUpdateBatchDTO;
import com.xbongbong.pro.transfer.pojo.dto.TransferUpdateByBusinessRuleDTO;
import com.xbongbong.pro.transfer.pojo.vo.TransferDeleteBatchVO;
import com.xbongbong.pro.transfer.pojo.vo.TransferResetInstockIdVO;
import com.xbongbong.saas.domain.entity.InstockProductEntity;
import com.xbongbong.saas.domain.entity.ProductBaseInfoEntity;
import com.xbongbong.saas.domain.entity.TransferProductEntity;
import com.xbongbong.saas.enums.UpdateDataTypeEnum;

import java.util.List;

/**
 * 调拨单业务处理
 * @author feng.zheng
 * @version v1.0
 * @date 2019/1/22
 * @since v1.0
 */
public interface TransferService {
    /**
     * 调拨单保存前saas特殊校验
     *
     * @param validateDataDTO saas特殊校验数据入参
     * @throws XbbException 业务异常
     * @author feng.zheng
     * @date 2019/1/18
     */
    void beforeSave(ValidateDataDTO validateDataDTO) throws XbbException;

    /**
     * 调拨单保存后逻辑
     *
     * @param saasFormSaveDTO saas保存数据
     * @throws XbbException 业务异常
     * @author feng.zheng
     */
    void afterSave(SaasFormSaveDTO saasFormSaveDTO) throws XbbException;


    /**
     * 批量删除调拨单
     * @author 吴峰
     * @date 2019/2/28 11:21
     * @param transferDeleteBatchDTO 传参
     * @return com.xbongbong.pro.transfer.pojo.vo.TransferDeleteBatchVO
     * @throws XbbException 业务异常
     */
    TransferDeleteBatchVO deleteBatch(TransferDeleteBatchDTO transferDeleteBatchDTO) throws XbbException;

    /**
     * 新建时格式化解释
     *
     * @param formatExplainDTO 入参
     * @throws XbbException 异常
     */
    void formatAddExplain(FormatExplainDTO formatExplainDTO) throws XbbException;

    /**
     * 删除入库单后重置调拨单单入库单Id
     * @author 吴峰
     * @date 2019/2/28 22:53
     * @param transferResetInstockIdDTO
     * @return com.xbongbong.pro.inventory.pojo.vo.TransferResetInstockIdVO
     * @throws XbbException 业务异常
     */
    TransferResetInstockIdVO resetInstockIdByIdIn(TransferResetInstockIdDTO transferResetInstockIdDTO) throws XbbException;

    /**
     * 格式化调拨单产品，显示给前端
     *
     * @param dataList            调拨单实体数据
     * @param saasAnalysisDataDTO 数据解析DTO
     * @author feng.zheng
     * @date 2019-02-01 15:19
     */
//    void formatProduct4Show(JSONObject dataList, SaasAnalysisDataDTO saasAnalysisDataDTO) throws XbbException;

    /**
     * 获取调拨单产品列表
     *
     * @param businessProductListDTO 入参
     * @param jsonObject 数据对象
     * @return 产品
     */
//    BusinessProductListVO getTransferProductList(BusinessProductListDTO businessProductListDTO, JSONObject jsonObject) throws XbbException;

    /**
     * 批量某个编辑
     * @author 吴峰
     * @date 2019/3/20 14:10
     * @param transferEditAttrUpdateDTO
     * @return void
     * @throws XbbException 业务异常
     */
    void batchEditAttr(TransferEditAttrUpdateDTO transferEditAttrUpdateDTO) throws XbbException;
    /**
     * 批量编辑
     * @author 吴峰
     * @date 2019/3/20 14:10
     * @param transferUpdateBatchDTO
     * @return void
     * @throws XbbException 业务异常
     */
    void updateBatch(TransferUpdateBatchDTO transferUpdateBatchDTO) throws XbbException;

    /**
     * 将Excel数据格式化成表单保存需要的JSON格式的数据
     *
     * @param importFormDataDTO 导入入参
     * @param titlePojoList     标题
     * @param rowGroupPojo      一个表单对应的一组Excel填写的数据
     * @param fieldAttrList     解释
     * @return FormDataAddDTO
     * @throws XbbException XbbException
     * @author lee
     * @date 2019/4/29 14:16
     * @since V1.0
     */
    FormDataAddDTO formatExcelValue(ImportFormDataDTO importFormDataDTO, List<CellTitlePojo> titlePojoList, RowGroupPojo rowGroupPojo, List<FieldAttrEntityForImport> fieldAttrList) throws XbbException;

    /**
     * 格式化导出值
     *
     * @param paasFormDataESList 数据
     * @throws XbbException 异常
     */
    void formatExportValue(List<PaasFormDataEntityExt> paasFormDataESList, FormDataListDTO formDataListDTO, List<FieldAttrEntityForImport> fieldAttrList) throws XbbException;

    /**
     * Description: 调拨单 仓库一致性同步
     * @param corpid
     * @param dataId
     * @param name
     * @return void
     * @author 魏荣杰
     * @date 2019/8/5 11:11
     * @since v1.0
     */
    void dataConsistencyUpdateWarehouse(String corpid, Long dataId, String name) throws XbbException;

    /**
     * 根据业务规则，更新调拨单
     * @author 吴峰
     * @date 2019/8/19 16:40
     * @param transferUpdateByBusinessRuleDTO
     * @return void
     * @throws XbbException 业务异常
     */
    void updateBatchByBusinessRule(TransferUpdateByBusinessRuleDTO transferUpdateByBusinessRuleDTO) throws XbbException;
    /**
     * 汇总调拨单产品信息（详情页，几种产品几件）
     *
     * @param businessProductListDTO 入参
     * @throws XbbException
     * @author long.rao
     * @date 2019-08-28 10:23
     */
    ProductSummaryVO summaryProductList(BusinessProductListDTO businessProductListDTO) throws XbbException;

    void formatProduct4Show2(Long dataId, String corpid, JSONObject data, Boolean forProcess, Integer operate, UpdateDataTypeEnum updateDataTypeEnum) throws XbbException;

    PagingProductVO getPagingProduct(PagingProductDTO pagingProductDTO) throws XbbException;

    JSONObject formatSingleProduct(TransferProductEntity entity, ProductBaseInfoEntity productBaseInfoEntity);

    /**
     * 调拨入库单保存后判断是否入库完毕
     *
     */
    boolean judgeTransferAllInBound(Long instockId, Long outstockId, Long refId, String corpid, List<ProductSavePojo> productSavePojoList) throws XbbException;

    /**
     * 维护调拨出库单已出库数量数据
     * @param corpid
     * @param productSavePojoList
     * @param isSave true保存 false 删除
     */
    void updateTransferOutstockNum(List<Long> refIds, String corpid, List<ProductSavePojo> productSavePojoList,Boolean isSave) throws XbbException;

    void formatBatchExplain(List<FieldAttrEntity> fieldAttrEntityList, String enable);

    /**
     * 维护调拨出库单已入库数量数据
     * @param corpid
     * @param productSavePojoList
     */
    void updateTransferInstockNum(List<Long> refIds, String corpid, List<ProductSavePojo> productSavePojoList, List<InstockProductEntity> instockProductEntities) throws XbbException;

    /**
     * 跟新调拨单开启关闭状态
     * @param changeDocumentStatusSaveDTO
     * @return
     */
    ChangeDocumentStatusSaveVO changeDocumentStatus(ChangeDocumentStatusSaveDTO changeDocumentStatusSaveDTO) throws XbbException;

    /**
     * 批量增删标签
     * @param addLabelDTO
     * @param addBatchList
     * @throws XbbException
     */
    void updateBatchLabelAttr(AddLabelDTO addLabelDTO, List<PaasFormDataEntityExt> addBatchList, Boolean addOrDelete) throws XbbException;

    void afterSaveForWorkflow(SaasFormSaveDTO saasFormSaveDTO) throws XbbException;

    void afterSaveForUpdateWorkflow(SaasFormSaveDTO saasFormSaveDTO) throws XbbException;
}
